﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TopArtMVC.Models
{
    public class PostView
    {
        private ApplicationDbContext db = new ApplicationDbContext();

        public int Post_ID { get; set; }
        public string UserName { get; set; }/*Post by, uploader username*/
        public string Title { get; set; }
        public string Artist { get; set; }
        public string Album { get; set; }
        public string Genre { get; set; }
        public string ImagePath { get; set; }
        public DateTime ReleseDate { get; set; }
        public string FacebookLink { get; set; }
        public string TwitterLink { get; set; }
        public string VideoLink { get; set; }
        public string YoutubeChannel { get; set; }
        public string GooglePlus { get; set; }
        public string EmbededData { get; set; }
        public int RatingID { get; set; }
        public int FiveStars { get; set; }
        public int FourStars { get; set; }
        public int ThreeStars { get; set; }
        public int TwoStars { get; set; }
        public int OneStars { get; set; }
        public int TotalStars { get; set; }
        public double AvgStars { get; set; }
        public DateTime PostDate { get; set; }
        public string PostText { get; set; }
        public PostView() { }

        /// <summary>
        /// following method will initialize a display object with only PostID
        /// </summary>
        /// <param name="PostID"></param>
        public PostView(int PostID)
        {
            Post post = db.Posts.Find(PostID);
            Song song =(Song) db.Songs.Where(s => s.PostID.Equals(PostID));
            Review review = (Review)db.Review.Where(s => s.PostID.Equals(PostID));//future use;
            Post_ID = PostID;
            UserName = "keshab"; //username who have posted it;
            Title = song.Title;
            Artist = "artistName"; // we have to figure out
            Album = song.Album_Name;
            Genre = song.Genre;
            ImagePath = "imagePath";//we have to figure out
            ReleseDate = song.ReleaseDate;
            FacebookLink = "facebook Link";//we have to fiture out
            TwitterLink = "twitter link";//we have to fiture out
            VideoLink = "video link";// have to figure
            YoutubeChannel = "youtube channel"; //have to do
            GooglePlus = "google plus";//have to fiture out
            EmbededData = "embeded data for song";//have to fiture out
            FiveStars = 30;
            FourStars = 20;
            ThreeStars = 34;
            TwoStars = 23;
            OneStars = 24;
            TotalStars = FiveStars + FourStars + ThreeStars + TwoStars + OneStars;
            AvgStars=((5*FiveStars)+(4*FourStars)+(3*ThreeStars)+(2*TwoStars)+OneStars)/TotalStars;
            PostDate = post.PostDate;
            PostText = post.PostText;
        }

        /// follwoing method will create list  of display for all posts

        public List<PostView> GetAllPosts()
        {
            List<Post>posts = db.Posts.ToList();
            List<PostView> myList = new List<PostView>();
            foreach (Post post in posts){
                PostView newPost=new PostView(post.ID);
                myList.Add(newPost);
            }
            return myList;
        }

        public List<PostView> searchWithinTitle(string search)
        {
            List<Song> songs = db.Songs.Where(s => s.Title.Contains(search)).ToList();
            List<PostView> myList = new List<PostView>();
            foreach (Song song in songs)
            {
                PostView newPost = new PostView(song.PostID);
                myList.Add(newPost);
            }
            return myList;
        }

        public List<PostView> searchWithinAlbum(string search)
        {
            List<Song> songs = db.Songs.Where(s => s.Album_Name.Contains(search)).ToList();
            List<PostView> myList = new List<PostView>();
            foreach (Song song in songs)
            {
                PostView newPost = new PostView(song.PostID);
                myList.Add(newPost);
            }
            return myList;
        }

        public List<PostView> searchWithinGenre(string search)
        {
            List<Song> songs = db.Songs.Where(s => s.Genre.Contains(search)).ToList();
            List<PostView> myList = new List<PostView>();
            foreach (Song song in songs)
            {
                PostView newPost = new PostView(song.PostID);
                myList.Add(newPost);
            }
            return myList;
        }

        public List<PostView> searchAll(string search)
        {
            var titleResults = searchWithinTitle(search);
            var albumResults = searchWithinAlbum(search);
            var genreResults = searchWithinGenre(search);

            var result = titleResults.Union(albumResults).ToList();
            result = result.Union(genreResults).ToList();
            return result;
        }
     /*   public List<PostView> searchWithinArtist(string search)
        {
            List<Song> songs = db.Songs.Where(s => s..Contains(search)).ToList();
            List<PostView> myList = new List<PostView>();
            foreach (Song song in songs)
            {
                PostView newPost = new PostView(song.PostID);
                myList.Add(newPost);
            }
            return myList;
        }
        */


    }

}